package com.linzhaowei.headhuntingservice.adapter;

import android.content.Context;
import android.content.Intent;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import com.linzhaowei.headhuntingservice.JobInformationUpdate;
import com.linzhaowei.headhuntingservice.R;
import com.linzhaowei.headhuntingservice.bean.JobInformation;
import java.util.List;

public class JobInformationSimpleAdapter extends RecyclerView.Adapter<JobInformationSimpleAdapter.ViewHolder>{
    private List<JobInformation> jobInformationList;
    private Context context;


    static class ViewHolder extends RecyclerView.ViewHolder{
        TextView job_name;
        TextView job_address;
        TextView job_salary;

        View job_view;


        ViewHolder(View view){
            super(view);
            job_view=view;
            job_name=view.findViewById(R.id.j_i_name);
            job_address=view.findViewById(R.id.j_i_address);
            job_salary=view.findViewById(R.id.j_i_salary);
        }
    }

    public JobInformationSimpleAdapter(List<JobInformation> list, Context context){
        jobInformationList=list;
        this.context=context;
    }

    @Override
    public JobInformationSimpleAdapter.ViewHolder onCreateViewHolder(final ViewGroup parent, int viewType){
        View view= LayoutInflater.from(parent.getContext())
                .inflate(R.layout.job_information_simple_item,parent,false);
        final JobInformationSimpleAdapter.ViewHolder holder=new JobInformationSimpleAdapter.ViewHolder(view);

        holder.job_view.setOnClickListener(v -> {
            int position=holder.getAdapterPosition();
            JobInformation jobInformation=jobInformationList.get(position);
            Intent intent=new Intent(context, JobInformationUpdate.class);
            intent.putExtra("jobInformation",jobInformation);
            context.startActivity(intent);
        });

        return holder;
    }

    @Override
    public void onBindViewHolder(JobInformationSimpleAdapter.ViewHolder holder, int position){
        JobInformation jobInformation=jobInformationList.get(position);
        holder.job_name.setText(jobInformation.getName());
        holder.job_address.setText(jobInformation.getAddress());
        holder.job_salary.setText(jobInformation.getSalary() +"/月");
    }

    @Override
    public int getItemCount(){
        return jobInformationList.size();
    }

}
